// 栈实现
class ArrayStack {
    private int[] data;
    private int top = -1;
    
    public ArrayStack(int capacity) {
        data = new int[capacity];
    }
    
    public void push(int value) {
        if (top == data.length - 1) {
            System.out.println("栈已满");
            return;
        }
        data[++top] = value;
    }
    
    public int pop() {
        if (isEmpty()) {
            System.out.println("栈为空");
            return -1;
        }
        return data[top--];
    }
    
    public int peek() {
        return isEmpty() ? -1 : data[top];
    }
    
    public boolean isEmpty() {
        return top == -1;
    }
}

// 队列实现
class ArrayQueue {
    private int[] data;
    private int front = 0, rear = 0;
    
    public ArrayQueue(int capacity) {
        data = new int[capacity + 1]; 
    }
    
    public void offer(int value) {
        if (isFull()) {
            System.out.println("队列已满");
            return;
        }
        data[rear] = value;
        rear = (rear + 1) % data.length;
    }
    
    public int poll() {
        if (isEmpty()) {
            System.out.println("队列为空");
            return -1;
        }
        int value = data[front];
        front = (front + 1) % data.length;
        return value;
    }
    
    public boolean isEmpty() {
        return front == rear;
    }
    
    public boolean isFull() {
        return (rear + 1) % data.length == front;
    }
}